<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ page import="com.easyui.common.UserLogin" %>

<%
	String pno = request.getParameter("pno");
%>


<script type="text/javascript"
	src="../js/jquery-easyui-1.3.5/jquery.min.js" charset="UTF-8"></script>
<script type="text/javascript"
	src="../js/jquery-easyui-1.3.5/jquery.easyui.min.js" charset="UTF-8"></script>
<link rel="stylesheet"
	href="../js/jquery-easyui-1.3.5/themes/default/easyui.css"
	type="text/css"></link>
<link rel="stylesheet" href="../js/jquery-easyui-1.3.5/themes/icon.css"
	type="text/css"></link>
<link rel="stylesheet" href="../css/main.css" type="text/css"></link>
<script type="text/javascript" src="../js/mine.js"></script>
<script type="text/javascript"
	src="../js/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"
	charset="UTF-8"></script>

<script type="text/javascript">
	var achiveLayout;
	var achiveDatagrid;
	$(function(){
		achiveLayout = $('#achiveLayout').layout();
		achiveDatagrid = $('#achiveDatagrid').datagrid({
			url:'../servlet/GetAchiveServlet?pno=' + <%= pno %>,
			fitColumns:true,
			nowrap:false,
			//striped:true,
			idField:'ano',
			pagination:true,
			pageSize:10,
			pageList:[10,20,30],
			fit:true,
			border:false,
			sortName:'uptime',
			sortOrder:'desc',
			//showFooter:true,
			columns:[[{
				field:'ano',
				checkbox:true
			},{
				title:'文件名',
				field:'aname',
				width:100,
				sortable:true
			},{
				title:'上传日期',
				field:'uptime',
				width:100,
				sortable:true
			},{
				title:'上传者',
				field:'upname',
				width:50
			},{
				title:'大小',
				field:'size',
				width:50
			},{
				title:'备注',
				field:'comment',
				width:100
			},{
				title:'下载',
				field:'download',
				width:50,
				formatter: function(value,rowData,rowIndex){
					 return '<a href="../servlet/DownloadServlet?ano=' + rowData.ano + '" >' + value +'</a>';
		     	}
			},{
				title:'删除',
				field:'delete',
				width:50,
				formatter: function(value,rowData,rowIndex){
					if(value != null) {
					 	return '<a href="#" onclick="deleteAttach(' + rowData.ano + ')" >' + value +'</a>';
					}
		     	}
			}]],
			toolbar:[{
				text:'上传',
				iconCls:'icon-add',
				handler:function(){
					addAchivement();
				}
			},'-',{
				text:'取消',
				iconCls:'icon-undo',
				handler:function(){
					achiveDatagrid.datagrid('unselectAll');
					achiveDatagrid.datagrid('rejectChanges');
				}
			},'-',{
				text:'刷新',
				iconCls:'icon-reload',
				handler:function(){
					achiveDatagrid.datagrid('unselectAll');
					achiveDatagrid.datagrid('rejectChanges');
					achiveDatagrid.datagrid('load',{});
				}
			},'-']
		});
	});
	
	deleteAttach = function(ano) {
		$.messager.confirm('提示','确定删除该文件吗?',function(b) {
			if(b) {
				$.ajax({
					url:'../servlet/DeleteAttachServlet',
					data:{
						ano:ano
					},
					type:'post',
					dataType:'json',
					success:function(r) {
						if(r && r.success) {
							achiveDatagrid.datagrid('acceptChanges');
							achiveDatagrid.datagrid('load');
							achiveDatagrid.datagrid('unselectAll');
							achiveDatagrid.datagrid('rejectChanges');
							//console.info(achiveDatagrid.datagrid('getSelections'));
							$.messager.show({
								title:'提示',
								msg:r.msg
							});
						} else {
							$.messager.alert('提示',r.msg,'error');
						}
					}
				});
			}
		});
	}
	
	addAchivement = function() {
		uploadDialog = parent.$('#uploadDialog', parent.document).dialog({
			title:'上传文件',
			modal:true,
			method:'post',
			collapsible:false,
			showHeader:false,
			width:700,
			height:400,
			href:'teacher/addAchivement.jsp?pno=' + <%= pno %>
		});
		
		uploadDialog.dialog('open');
	}
</script>
<div id="achiveLayout" fit="true" border="false">
	<div region="center" border="false" >
		<table id="achiveDatagrid"></table>
	</div>
</div>
